package com.sphd.emanu.activity.staff;

import android.content.Context;

import com.google.gson.JsonObject;
import com.sphd.emanu.mvp.BasePresenterImpl;
import com.wzutils.L;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @Author Hu
 * @Time 2017/7/25 -- 19:41.
 * @Email 87683202@qq.com
 */

public class StaffPresenter extends BasePresenterImpl<StaffContract.View> implements StaffContract.Presenter {

    @Override
    public void deleteUser(Integer id) {
        emanuService.deleteUser(id).enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                L.e(response.toString());
                int res = res(response);
                mView.recRes(res);
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
            }
        });
    }

    @Override
    public void addUser(String mobile, Integer oid, Integer roleid, String rolename, String logonname, String logonpwd, String username) {
        emanuService.addUser(mobile, oid, roleid, rolename, logonname, logonpwd, username).enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                L.e(response.toString());
                int res = res(response);
                mView.recRes(res);
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
            }
        });
    }

    @Override
    public void updateUser(Integer id, String mobile, Integer oid, Integer roleid, String rolename, String logonname, String logonpwd, String username) {

        emanuService.updateUser(id, mobile, oid, roleid, rolename, logonname, logonpwd, username).enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                L.e(response.toString());
                int res = res(response);
                mView.recRes(res);
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
            }
        });
    }
}
